#!/usr/bin/env python
# coding=utf-8
import os
from log.logUtils import logger

import pytest
import allure


@allure.feature('53错题本')  # 用feature说明产品需求，可以理解为JIRA中的Epic
class TestShoppingTrolley(object):
    @allure.story('加入错题本')  # 用story说明用户场景，可以理解为JIRA中的Story
    def test_add_shopping_trolley(self):
        login('Young', '123456')  # 步骤1，调用“step函数”
        with allure.step("浏览图书"):  # 步骤2，step的参数将会打印到测试报告中
            allure.attach('习题1、2、3', '物理')  # attach可以打印一些附加信息
            allure.attach('习题4、5、6', '化学')
            assert 11 == 11
        with allure.step("添加错题"):  # 步骤3
            assert 5 == 5
            pass
        with allure.step("校验结果"):  # 步骤4
            allure.attach('添加错题成功', '期望结果')
            assert 1 == 1
            allure.attach('添加错题失败', '实际结果')
            assert 'success' == 'failed'

    @allure.story('修改错题本')
    def test_edit_shopping_trolley(self):
        assert 1 == 1
        assert 2 == 2
        assert 3 == 3
        pass

    @pytest.mark.skipif(reason='本次不执行')
    @allure.story('删除错题本')
    def test_delete_shopping_trolley(self):
        assert 0 == 0
        pass


@allure.step('用户登录')  # 将函数作为一个步骤，调用此函数时，报告中输出这个步骤，我把这样的函数叫“step函数”
def login(user, pwd):
    logger.debug(user, pwd)


if __name__ == '__main__':
    '''
    D:\\user\\workspace\\py_workspace\\APIAutomationFramework>pytest -s -q --alluredir  result   ./test/111test_demo.py
     allure generate ./result -o ./report  --clean
    '''
    # pytest.main(["-v","test03.py",'--alluredir','result'])
    # 生成测试报告json

    logger.debug(os.path.dirname(__file__))
    # pytest.main(["-s", "-q", '--alluredir', 'result', './test/111test_demo.py'])

    result = os.path.dirname(os.path.dirname(__file__)) + '/result'
    pytest.main(["-s", "-q", '--alluredir', result, os.path.dirname(__file__)])
    # #os.system("allure" "generate","./result/","-o","./report/html")
    # 将测试报告转为html格式

    report = os.path.dirname(os.path.dirname(__file__)) + '/report'
    split = 'allure ' + 'generate ' + result + ' -o ' + report + ' --clean'
    os.system('cd ' + os.path.dirname(os.path.dirname(__file__)))
    os.system(split)
    logger.debug(split)
